/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DigitalMap.java
 *
 * Created on 21/07/2010, 12:51:46 PM
 */

package com.pstreets.gisengine.demo;

import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;

import com.mapdigit.gis.MapDirection;
import com.mapdigit.gis.MapLayer;
import com.mapdigit.gis.MapPoint;
import com.mapdigit.gis.drawing.IGraphics;
import com.mapdigit.gis.drawing.IImage;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.location.ChinaMapOffset;
import com.mapdigit.gis.raster.IMapDrawingListener;
import com.mapdigit.gis.raster.IReaderListener;
import com.mapdigit.gis.raster.MapConfiguration;
import com.mapdigit.gis.raster.MapTileDownloadManager;
import com.mapdigit.gis.raster.MapType;
import com.mapdigit.gis.raster.RasterMap;
import com.mapdigit.gis.service.IGeocodingListener;
import com.mapdigit.gis.service.IReverseGeocodingListener;
import com.mapdigit.gis.service.IRoutingListener;
import com.pstreets.common.drawing.JavaSEGraphicsFactory;

@SuppressWarnings("serial")
public class DigitalMap extends javax.swing.JFrame implements IReaderListener,
        IMapDrawingListener,IRoutingListener,IGeocodingListener,IReverseGeocodingListener {

    private RasterMap map;
    private MapTileDownloadManager mapTileDownloadManager;
    private ChinaMapOffset mapOffset=new ChinaMapOffset();

    public static String getHexString(byte b) throws Exception {
        String result=
                    Integer.toString((b & 0xff) + 0x100, 16).substring(1);
        if(result.length()==1) result="0" +result;
        return "0x"+result.toUpperCase();
    }

    /** Creates new form DigitalMap */
    public DigitalMap() {
        initComponents();

        //setDefaultProxy();
        MapLayer.setAbstractGraphicsFactory(JavaSEGraphicsFactory.getInstance());
        MapType.setCustomMapTileUrl(new CustomMapType());
        MapConfiguration.setParameter(MapConfiguration.WORKER_THREAD_NUMBER, 16);
        mapTileDownloadManager = new MapTileDownloadManager(this);
        map = new RasterMap(2048, 2048, mapTileDownloadManager);
        map.setScreenSize(mapLabel.getWidth(), mapLabel.getHeight());
        mapTileDownloadManager.start();
        map.setMapDrawingListener(this);
        GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
        map.setCenter(center, 4, MapType.MICROSOFTCHINA);
        map.setRoutingListener(this);
        map.setGeocodingListener(this);
        map.setReverseGeocodingListener(this);
    }

    
    private void panMap(int x, int y) {
        int dx = x - oldX;
        int dy = y - oldY;
        map.panDirection(dx, dy);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mapLabel = new javax.swing.JLabel();
        btnRight = new javax.swing.JButton();
        btnDown = new javax.swing.JButton();
        btnLeft = new javax.swing.JButton();
        btnUp = new javax.swing.JButton();
        btnZoomIn = new javax.swing.JButton();
        bthGetDirection = new javax.swing.JButton();
        btnZoomOut = new javax.swing.JButton();
        btnFindAddress = new javax.swing.JButton();
        txtAddress = new javax.swing.JTextField();
        txtAddress1 = new javax.swing.JTextField();
        txtAddress2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cboMapType = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        txtLocation = new javax.swing.JTextField();
        chkChina = new javax.swing.JCheckBox();
        btnGoto = new javax.swing.JButton();
        lblLocation = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("引路蜂地图示例");
        setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        setResizable(false);

        mapLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        mapLabel.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
            public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
                mapLabelMouseWheelMoved(evt);
            }
        });
        mapLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mapLabelMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                mapLabelMouseReleased(evt);
            }
        });
        mapLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                mapLabelMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                mapLabelMouseMoved(evt);
            }
        });

        btnRight.setText("右");
        btnRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRightActionPerformed(evt);
            }
        });

        btnDown.setText("下");
        btnDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDownActionPerformed(evt);
            }
        });

        btnLeft.setText("左");
        btnLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLeftActionPerformed(evt);
            }
        });

        btnUp.setText("上");
        btnUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpActionPerformed(evt);
            }
        });

        btnZoomIn.setText("放大");
        btnZoomIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnZoomInActionPerformed(evt);
            }
        });

        bthGetDirection.setText("获取路径");
        bthGetDirection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bthGetDirectionActionPerformed(evt);
            }
        });

        btnZoomOut.setText("缩小");
        btnZoomOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnZoomOutActionPerformed(evt);
            }
        });

        btnFindAddress.setText("查找地址");
        btnFindAddress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindAddressActionPerformed(evt);
            }
        });

        jLabel1.setText("地图类型");

        cboMapType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Google Map", "Google Map China", "Google terren Map", "Google Satellite Map", "Google Hybrid Map", "Microsoft Map", "Microsoft China Map", "Microsoft Satellite Map", "Microsoft Hybrid Map", "Microsoft terren Map", "Yahoo Map", "Yahoo Satellite Map", "Yahoo Hybrid Map", "MapABC China Map", "OpenStreet Map", "OpenStreet Cycle Map", "OpenStreet OSM Map", "QQ Map", " ", " ", " " }));
        cboMapType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboMapTypeActionPerformed(evt);
            }
        });

        jLabel2.setText("经度，纬度");

        chkChina.setText("中国");

        btnGoto.setText("转到");
        btnGoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGotoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(mapLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 768, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(btnZoomIn)
                                    .addGap(45, 45, 45)
                                    .addComponent(btnZoomOut))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(btnLeft)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(btnDown)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(btnRight))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(bthGetDirection)
                                    .addGap(16, 16, 16))
                                .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                                .addComponent(txtAddress1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                                .addComponent(txtAddress2, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(60, 60, 60)
                                    .addComponent(btnUp, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnFindAddress)))
                        .addGap(53, 53, 53))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(26, 26, 26)
                                        .addComponent(jLabel1)
                                        .addGap(18, 18, 18)
                                        .addComponent(cboMapType, 0, 184, Short.MAX_VALUE)
                                        .addGap(13, 13, 13))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(chkChina))
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnGoto, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap())
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20))))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(mapLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 768, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(btnUp)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addComponent(btnDown))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnRight)
                                    .addComponent(btnLeft))))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnZoomIn)
                            .addComponent(btnZoomOut))
                        .addGap(26, 26, 26)
                        .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9)
                        .addComponent(btnFindAddress)
                        .addGap(21, 21, 21)
                        .addComponent(txtAddress1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAddress2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(bthGetDirection)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cboMapType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(chkChina))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnGoto)
                        .addGap(81, 81, 81)
                        .addComponent(lblLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRightActionPerformed
        map.panDirection(-32, 0);
}//GEN-LAST:event_btnRightActionPerformed

    private void btnDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownActionPerformed
        map.panDirection(0, -32);
}//GEN-LAST:event_btnDownActionPerformed

    private void btnLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeftActionPerformed
        map.panDirection(32, 0);
}//GEN-LAST:event_btnLeftActionPerformed

    private void btnUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpActionPerformed
        map.panDirection(0, 32);
}//GEN-LAST:event_btnUpActionPerformed

    private void btnZoomInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnZoomInActionPerformed
        map.zoomIn();
}//GEN-LAST:event_btnZoomInActionPerformed

    private void bthGetDirectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bthGetDirectionActionPerformed
        if (!txtAddress1.getText().isEmpty() && !txtAddress2.getText().isEmpty()) {
            String name1=txtAddress1.getText();
            String name2=txtAddress2.getText();
//            try {
//                name1 = com.mapdigit.util.HTML2Text.encodeutf8(name1.getBytes("utf-8"));
//                name2 = com.mapdigit.util.HTML2Text.encodeutf8(name2.getBytes("utf-8"));
//            } catch (UnsupportedEncodingException ex) {
//
//            }
        map.getDirections("from: " + name1+ " to: " +name2);
        }
        //String address="118.7788905,32.0418381,121.455207,31.248674,116.427276,39.90372,117.180908,39.11643";
        //String address="118.7788905,32.0418381,117.180908,39.11643";
        //map.getDirections(address);
       // GeoLatLng latLng1=new GeoLatLng(32.0418381,118.7788905);
       // GeoLatLng latLng2=new GeoLatLng(39.11643,117.180908);
       // map.getDirections(new GeoLatLng[]{latLng1,latLng2});
}//GEN-LAST:event_bthGetDirectionActionPerformed

    private void btnZoomOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnZoomOutActionPerformed
        map.zoomOut();
}//GEN-LAST:event_btnZoomOutActionPerformed

    private void btnFindAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindAddressActionPerformed
        if (!txtAddress.getText().isEmpty()) {
            String name=txtAddress.getText();

            
            map.getLocations(name);

            //map.getReverseLocations("51.51384, -0.10952");
           // GeoLatLng center=new GeoLatLng(52.46882, 13.38046);
           // GeoBounds bounds =new GeoBounds(center,new GeoSize(0.02,0.02));
           // map.getLocations(name, 0, center, bounds);
        }
}//GEN-LAST:event_btnFindAddressActionPerformed

    private void cboMapTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboMapTypeActionPerformed
        // TODO add your handling code here:
        switch(cboMapType.getSelectedIndex()){
            case 0:
                map.setMapType(MapType.GOOGLEMAP);
                break;
            case 1:
                map.setMapType(MapType.GOOGLECHINA);
                break;
            case 2:
                map.setMapType(MapType.GOOGLETERREN);
                break;
            case 3:
                map.setMapType(MapType.GOOGLESATELLITE);
                break;
            case 4:
                map.setMapType(MapType.GOOGLEHYBRID);
                break;
            case 5:
                map.setMapType(MapType.MICROSOFTMAP);
                break;
            case 6:
                map.setMapType(MapType.MICROSOFTCHINA);
                break;
            case 7:
                map.setMapType(MapType.MICROSOFTSATELLITE);
                break;
            case 8:
                map.setMapType(MapType.MICROSOFTHYBRID);
                break;
            case 9:
                map.setMapType(MapType.MICROSOFTTERREN);
                break;
            case 10:
                map.setMapType(MapType.YAHOOMAP);
                break;
            case 11:
                map.setMapType(MapType.YAHOOSATELLITE);
                break;
            case 12:
                map.setMapType(MapType.YAHOOHYBRID);
                break;
            case 13:
                map.setMapType(MapType.MAPABCCHINA);
                break;
            case 14:
                map.setMapType(MapType.OPENSTREETMAP);
                break;
            case 15:
                map.setMapType(MapType.OPENCYCLEMAP);
                break;
            case 16:
                map.setMapType(MapType.OSMAMAP);
                break;
            case 17:
               map.setMapType(MapType.GENERIC_MAPTYPE_5);
                break;

        }
    }//GEN-LAST:event_cboMapTypeActionPerformed

    private boolean isPanMode=false;

    private void mapLabelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mapLabelMousePressed
        oldX = evt.getX();
                oldY = evt.getY();
                isPanMode=true;
    }//GEN-LAST:event_mapLabelMousePressed

    private void mapLabelMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mapLabelMouseMoved
        
    }//GEN-LAST:event_mapLabelMouseMoved

    private void mapLabelMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mapLabelMouseReleased
        oldX = evt.getX();
                oldY = evt.getY();
                isPanMode=false;
    }//GEN-LAST:event_mapLabelMouseReleased

    private void mapLabelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mapLabelMouseDragged
        if(isPanMode)
        {
        panMap(evt.getX(), evt.getY());
                oldX = evt.getX();
                oldY = evt.getY();
        }
    }//GEN-LAST:event_mapLabelMouseDragged

    private void mapLabelMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_mapLabelMouseWheelMoved
        int v=evt.getWheelRotation();
        if(v<0) map.zoomIn();
        else
            map.zoomOut();
    }//GEN-LAST:event_mapLabelMouseWheelMoved

    private void btnGotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGotoActionPerformed
        // TODO add your handling code here:
        GeoLatLng latLng1;
        try{
        String location="["+txtLocation.getText()+",0]";
        GeoLatLng latLng=MapLayer.fromStringToLatLng(location);
        latLng1=latLng;
        if(chkChina.isSelected()){
            latLng1=mapOffset.fromEarthToMars(latLng);
            lblLocation.setText(latLng1.toString());
        }
        map.panTo(latLng1);
        }catch(Exception e){}
    }//GEN-LAST:event_btnGotoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bthGetDirection;
    private javax.swing.JButton btnDown;
    private javax.swing.JButton btnFindAddress;
    private javax.swing.JButton btnGoto;
    private javax.swing.JButton btnLeft;
    private javax.swing.JButton btnRight;
    private javax.swing.JButton btnUp;
    private javax.swing.JButton btnZoomIn;
    private javax.swing.JButton btnZoomOut;
    @SuppressWarnings("rawtypes")
	private javax.swing.JComboBox cboMapType;
    private javax.swing.JCheckBox chkChina;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblLocation;
    private javax.swing.JLabel mapLabel;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtAddress1;
    private javax.swing.JTextField txtAddress2;
    private javax.swing.JTextField txtLocation;
    // End of variables declaration//GEN-END:variables

    private int oldX = -1;
    private int oldY = -1;

      public void readProgress(int arg0, int arg1) {
        //System.out.println(arg0 + "/" + arg1);
    }


    private void drawCursor(IGraphics g)  {
        int x = mapLabel.getWidth() / 2;
            int y = mapLabel.getHeight() / 2;
        g.setColor(0x205020);
                g.drawRect(x - 4, y - 4, 8, 8);
                g.drawLine(x, y - 6, x, y - 2);
                g.drawLine(x, y + 6, x, y + 2);
                g.drawLine(x - 6, y, x - 2, y);
                g.drawLine(x + 6, y, x + 2, y);
    }
    public void done() {
        //System.out.println("done");
        IImage mapImage = MapLayer.getAbstractGraphicsFactory().createImage(mapLabel.getWidth(), mapLabel.getHeight());
        IGraphics mapGraphics = mapImage.getGraphics();
        map.paint(mapGraphics);
        drawCursor(mapGraphics);
        ImageIcon imageIcon = new ImageIcon((BufferedImage) mapImage.getNativeImage());
        mapLabel.setIcon(imageIcon);
    }

    public void done(String arg0, MapDirection result) {
        if(result!=null){
            map.setMapDirection(result);
            map.resize(result.getBound());
        }
    }

    public void done(String query, MapPoint[] result) {
        if(result!=null){
           map.panTo(result[0].getPoint());
        }

    }
}
